package com.tianqu.tms.www.finance.action;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.finance.actionform.TransferFeeManagementForm;
import com.tianqu.tms.www.finance.controller.TransferFeeManagementSearchResultController;
import com.tianqu.tms.www.finance.viewhelper.TransferFeeManagementViewHelper;

public class TransferFeeManagementSearchResultAction  extends TmsAction {
	private Logger logger = Logger.getLogger(TransferFeeManagementSearchResultAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		TransferFeeManagementForm inputForm = (TransferFeeManagementForm)form;
		if(StringUtil.isNullOrBlank(inputForm.getAccessCardNo()))
		{
			setErrorsToRequest(request, TmsConstants.U0040, null);
			return mapping.getInputForward();
		}
		
		TransferFeeManagementViewHelper view = new TransferFeeManagementViewHelper ();
		view.setAccessCardNo(inputForm.getAccessCardNo());
		view.setType(inputForm.getType());
		uc.setAttribute(TmsConstants.VIEWHELP, view);
		TransferFeeManagementSearchResultController controller = new TransferFeeManagementSearchResultController();
		controller.execute(uc);
		//
		view = (TransferFeeManagementViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		String member = view.getMemberId();
		if(StringUtil.isNullOrBlank(member))
		{
			setErrorsToRequest(request, TmsConstants.U4004, null);
			return mapping.getInputForward();
		}
		view.setPrintButtonShow("0");
		if(StringUtil.isNullOrBlank(inputForm.getAction()) || StringUtil.isNullOrBlank(inputForm.getRemark())) {
			if("1".equals(inputForm.getType())) {
				view.setRemark("过户费充值");
			}else {
				view.setRemark("过户费余额退费");
			}
			view.setPrice("1");
			view.setSaveButtonDisable("0");
		}else {
			view.setRemark(inputForm.getRemark());
			view.setPrice(inputForm.getPrice());
			view.setSaveButtonDisable("1");
			if("1".equals(inputForm.getType())) view.setPrintButtonShow("1");
		}
		view.setInsertTimeStr(StringUtil.getTimeByTimeStamp(new Timestamp(System.currentTimeMillis())));
		request.setAttribute(TmsConstants.VIEWHELP, view);
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
